package com.baofu.paycore.service.processor.preAuth;

import com.baofu.paycore.common.enums.FundTypeEnum;
import com.baofu.paycore.manager.model.preAuth.PreAuthBO;
import com.baofu.paycore.manager.model.preAuth.SubPreAuthBO;
import com.baofu.paycore.service.converter.DTO2BOConverter;
import com.baofu.paycore.service.facade.model.authorize.AuthorizeDTO;
import com.baofu.paycore.service.processor.PayBaseProcessor;
import com.google.common.collect.Lists;
import com.system.commons.sequence.redis.SequenceFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 预授权子资金单
 *
 * User: xin deng  Date: 16/8/30 ProjectName: paycore Version: 1.0
 */
@Component
public class SubPreAuthProcessor implements PayBaseProcessor<PreAuthBO, AuthorizeDTO> {

    /**
     * 资金单明细NO
     */
    @Autowired
    private SequenceFacade sequenceFacade;

    /**
     * 支付内部对象构建
     *
     * @param preAuthBO  支付模型
     * @param payBaseDTO 请求参数
     */
    @Override
    public PayBaseProcessor process(PreAuthBO preAuthBO, AuthorizeDTO payBaseDTO) {
        SubPreAuthBO subPreAuthBO = DTO2BOConverter.subPreAuthDTOToBO(payBaseDTO);
        subPreAuthBO.setPayNo(preAuthBO.getPayNo());
        subPreAuthBO.setFundDetailNo(sequenceFacade.getUniqueSeq());
        //冻结单号
        subPreAuthBO.setFreezeNo(sequenceFacade.getUniqueSeq());
        subPreAuthBO.setFundType(FundTypeEnum.PRE_AUTH.getCode());

        preAuthBO.setSubPreAuthBO(Lists.newArrayList(subPreAuthBO));
        return this;
    }
}
